#ifndef FS_FS_H
#define FS_FS_H
#include "stdint.h"
// 每个分区最多支持文件数
#define MAX_FILES_PER_PART 4096

#define BITS_PER_SECTOR 4096 // 扇区bit数
#define SECTOR_SIZE 512      // 扇区字节数
#define BLOCK_SIZE SECTOR_SIZE // 块大小
#define MAX_PATH_LEN 512

enum file_type {
    FT_UNKNOWN,
    FT_REGULAR,
    FT_DIRECTORY
};

enum oflags {
    O_RDONLY,   // 000b
    O_WRONLY,   // 001b
    O_RDWR,     // 010b
    O_CREAT = 4 // 100b
};

/* 文件读写位置偏移量 */
enum whence {
    SEEK_SET = 1,
    SEEK_CUR,
    SEEK_END
};

/* 文件属性结构体 */
struct stat {
    uint32_t st_ino;
    uint32_t st_size;
    enum file_type st_filetype;
};

/* 表示查找过程中, 文件的路径 */
struct path_search_record {
    char searched_path[MAX_PATH_LEN];
    struct dir* parent_dir;
    enum file_type file_type; // 找到的文件属性
};

extern struct partition* cur_part;
/* 函数声明 */
void filesys_init();
int32_t sys_open(const char*, enum oflags);
int32_t path_depth_cnt(char* pathname);
int32_t sys_write(int32_t fd, const void* buf, uint32_t count);
int32_t sys_close(int32_t fd);
int32_t sys_read(int32_t fd, void *buf, uint32_t count);
int32_t sys_lseek(int32_t fd, int32_t offset, uint8_t lflag);
int32_t sys_unlink(const char *pathname);
int32_t sys_mkdir(const char* pathname);
struct dir* sys_opendir(const char *name);
int32_t sys_closedir(struct dir *dir);
struct dir_entry *sys_readdir(struct dir *dir);
void sys_rewinddir(struct dir *dir);
int32_t sys_rmdir(const char *pathname);
char *sys_getcwd(char *buf, uint32_t size);
int32_t sys_chdir(const char *path);
int32_t sys_stat(const char *path, struct stat *buf);
void sys_putchar(char char_asci);
char* path_parse(char* pathname, char* name_store);
#endif // FS_FS_H